/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.startup.musicstore.services.Impl;

import com.startup.musicstore.app.facade.Facade;
import com.startup.musicstore.model.Album;
import com.startup.musicstore.model.AlbumCategory;
import com.startup.musicstore.services.SalesService;
import com.startup.musicstore.services.crud.AlbumCategoryCrudService;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author aljay19
 */
@Service("salesService")
@Transactional
public class SalesServiceImpl implements SalesService {
    
    private Facade data = new Facade();
    
    AlbumCategoryCrudService albumCategoryCrudService;

    @Override
    public String listCategoryWithMostSales() {
        
        int initialTotalSales = 0;
        String categoryName = "";
        albumCategoryCrudService = data.getAlbumCategoryCrudService();
        List<AlbumCategory> albumCategorys =albumCategoryCrudService.findAll();
        for(AlbumCategory ac: albumCategorys){
            int totalSales = 0;
            List<Album> albums = ac.getAlbums();
            for(Album a: albums){
                totalSales += a.getSales();
            }
            if(initialTotalSales < totalSales){
                initialTotalSales = totalSales;
                categoryName = ac.getCategoryName();
            }
        }
        return categoryName;
    }
    
}
